<template>
  <div class="register-page">
    <!-- 动态背景系统 -->
    <canvas ref="backgroundCanvas" class="background-canvas"></canvas>
    
    <!-- 高级动态背景 -->
    <div class="dynamic-background">
      <!-- 星云效果 -->
      <div class="nebula-container">
        <div class="nebula nebula-1"></div>
        <div class="nebula nebula-2"></div>
        <div class="nebula nebula-3"></div>
      </div>
      
      <!-- 流星雨 -->
      <div class="meteor-shower">
        <div class="meteor meteor-1"></div>
        <div class="meteor meteor-2"></div>
        <div class="meteor meteor-3"></div>
        <div class="meteor meteor-4"></div>
        <div class="meteor meteor-5"></div>
      </div>
      
      <!-- 动态光环 -->
      <div class="ring-system">
        <div class="ring ring-1"></div>
        <div class="ring ring-2"></div>
        <div class="ring ring-3"></div>
      </div>
      
      <!-- 螺旋星系 -->
      <div class="galaxy-spiral">
        <div class="spiral-arm arm-1"></div>
        <div class="spiral-arm arm-2"></div>
        <div class="spiral-arm arm-3"></div>
        <div class="spiral-arm arm-4"></div>
      </div>
      
      <!-- 闪烁星群 -->
      <div class="star-cluster">
        <div class="cluster-star" v-for="n in 50" :key="'cluster-' + n"></div>
      </div>
    </div>
    
    <div class="register-container">
      <!-- 注册表单卡片 -->
      <div class="register-card">
        <!-- 卡片装饰 -->
        <div class="card-decoration">
          <div class="decoration-orbit orbit-1"></div>
          <div class="decoration-orbit orbit-2"></div>
          <div class="decoration-particle particle-1"></div>
          <div class="decoration-particle particle-2"></div>
          <div class="decoration-particle particle-3"></div>
        </div>
        
        <div class="register-header">
          <div class="logo-section">
            <div class="logo-container">
              <div class="logo-bg"></div>
              <div class="logo-icon">🚀</div>
            </div>
            <h2>创建账户</h2>
          </div>
          <p>开启您的涂色征程</p>
        </div>

        <form @submit.prevent="handleRegister" class="register-form">
          <!-- 用户名输入 -->
          <div class="form-group">
            <div class="input-wrapper">
              <svg class="input-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M12 12C14.21 12 16 10.21 16 8C16 5.79 14.21 4 12 4C9.79 4 8 5.79 8 8C8 10.21 9.79 12 12 12ZM12 14C9.33 14 4 15.34 4 18V20H20V18C20 15.34 14.67 14 12 14Z" fill="currentColor"/>
              </svg>
              <input
                id="username"
                v-model="registerForm.username"
                type="text"
                placeholder="用户名 (3-20个字符)"
                class="styled-input"
                :class="{ 'error': errors.username }"
                required
              />
              <div class="input-underline"></div>
            </div>
            <span v-if="errors.username" class="error-text">{{ errors.username }}</span>
          </div>

          <!-- 密码输入 -->
          <div class="form-group">
            <div class="input-wrapper">
              <svg class="input-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M6 10V8C6 5.79 7.79 4 10 4H14C16.21 4 18 5.79 18 8V10H19C20.1 10 21 10.9 21 12V20C21 21.1 20.1 22 19 22H5C3.9 22 3 21.1 3 20V12C3 10.9 3.9 10 5 10H6ZM8 8V10H16V8C16 6.9 15.1 6 14 6H10C8.9 6 8 6.9 8 8Z" fill="currentColor"/>
              </svg>
              <input
                id="password"
                v-model="registerForm.password"
                type="password"
                placeholder="密码 (6-20个字符)"
                class="styled-input"
                :class="{ 'error': errors.password }"
                required
              />
              <div class="input-underline"></div>
            </div>
            <span v-if="errors.password" class="error-text">{{ errors.password }}</span>
          </div>

          <!-- 确认密码 -->
          <div class="form-group">
            <div class="input-wrapper">
              <svg class="input-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M9 12L11 14L15 10M21 12C21 16.97 16.97 21 12 21C7.03 21 3 16.97 3 12C3 7.03 7.03 3 12 3C16.97 3 21 7.03 21 12Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
              </svg>
              <input
                id="confirmPassword"
                v-model="registerForm.confirmPassword"
                type="password"
                placeholder="确认密码"
                class="styled-input"
                :class="{ 'error': errors.confirmPassword }"
                required
              />
              <div class="input-underline"></div>
            </div>
            <span v-if="errors.confirmPassword" class="error-text">{{ errors.confirmPassword }}</span>
          </div>

          <!-- 头像选择 -->
          <div class="form-group">
            <div class="avatar-section">
              <div class="section-label">
                <svg class="label-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                  <path d="M12 2C13.1 2 14 2.9 14 4C14 5.1 13.1 6 12 6C10.9 6 10 5.1 10 4C10 2.9 10.9 2 12 2ZM12 20C7.59 20 4 16.41 4 12C4 7.59 7.59 4 12 4C16.41 4 20 7.59 20 12C20 16.41 16.41 20 12 20ZM12 6C8.69 6 6 8.69 6 12C6 15.31 8.69 18 12 18C15.31 18 18 15.31 18 12C18 8.69 15.31 6 12 6Z" fill="currentColor"/>
                </svg>
                <span>选择您的头像</span>
              </div>
              <div class="avatar-grid">
                <div 
                  v-for="avatar in avatarOptions" 
                  :key="avatar.id"
                  class="avatar-option"
                  :class="{ 'selected': registerForm.avatar === avatar.id }"
                  @click="selectAvatar(avatar.id)"
                >
                  <div class="avatar-frame">
                    <img :src="avatar.url" alt="头像" class="avatar-image"/>
                    <div class="avatar-overlay">
                      <svg class="check-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <path d="M9 12L11 14L15 10M21 12C21 16.97 16.97 21 12 21C7.03 21 3 16.97 3 12C3 7.03 7.03 3 12 3C16.97 3 21 7.03 21 12Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                      </svg>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>

                    <!-- 用户协议 -->
          <div class="form-group">
            <div class="agreement-wrapper">
              <label class="agreement-label">
                <input
                  v-model="registerForm.agreeTerms"
                  type="checkbox"
                  class="agreement-checkbox"
                  required
                />
                <span class="checkmark">
                  <svg class="check-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M9 12L11 14L15 10" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                  </svg>
                </span>
                <span class="agreement-text">
                  我已阅读并同意
                  <a href="#" @click.prevent="showTerms" class="agreement-link">《用户协议》</a>
                  和
                  <a href="#" @click.prevent="showPrivacy" class="agreement-link">《隐私政策》</a>
                </span>
              </label>
            </div>
          </div>

          <!-- 注册按钮 -->
          <button
            type="submit"
            class="register-button"
            :disabled="isLoading || !registerForm.agreeTerms"
          >
            <span v-if="isLoading" class="button-content">
              <div class="loading-spinner"></div>
              创建中...
            </span>
            <span v-else class="button-content">
              <svg class="button-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M13 2L3 14H12L11 22L21 10H12L13 2Z" fill="currentColor"/>
              </svg>
              立即注册
            </span>
          </button>
        </form>

        <!-- 登录链接 -->
        <div class="card-footer">
          <div class="login-link">
            <span>已有账号？</span>
            <router-link to="/auth/login" class="footer-link">立即登录</router-link>
          </div>
        </div>

        <!-- 快速操作 -->
        <div class="quick-actions">
          <div class="divider">
            <span>或者</span>
          </div>
          <router-link to="/" class="back-home-btn">
            <svg class="btn-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
              <path d="M10 20V14H14V20H19V12H22L12 3L2 12H5V20H10Z" fill="currentColor"/>
            </svg>
            返回首页
          </router-link>
        </div>
      </div>
    </div>

    <!-- 协议模态框 -->
    <div v-if="showModal" class="modal-overlay" @click="closeModal">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>{{ modalTitle }}</h3>
          <button @click="closeModal" class="close-btn">&times;</button>
        </div>
        <div class="modal-body">
          <div v-if="modalType === 'terms'" class="terms-content">
            <h4>用户协议</h4>
            <p>欢迎使用涂色抢地盘游戏！请仔细阅读以下条款：</p>
            <ul>
              <li>用户必须年满13周岁才能注册账号</li>
              <li>禁止使用外挂、作弊软件等违规工具</li>
              <li>禁止发布违法、有害、骚扰性内容</li>
              <li>尊重其他玩家，维护良好的游戏环境</li>
              <li>我们保留对违规账号进行处罚的权利</li>
            </ul>
          </div>
          <div v-else class="privacy-content">
            <h4>隐私政策</h4>
            <p>我们重视您的隐私保护：</p>
            <ul>
              <li>我们仅收集游戏运行必需的基本信息</li>
              <li>不会将您的个人信息出售给第三方</li>
              <li>游戏数据仅用于提供更好的游戏体验</li>
              <li>您可以随时删除账号和相关数据</li>
              <li>我们采用加密技术保护您的数据安全</li>
            </ul>
          </div>
        </div>
        <div class="modal-footer">
          <button @click="closeModal" class="btn">我知道了</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const fileInput = ref(null)
const backgroundCanvas = ref(null)

// 表单数据
const registerForm = reactive({
  username: '',
  password: '',
  confirmPassword: '',
  avatar: '1',
  agreeTerms: false
})

// 错误信息
const errors = reactive({
  username: '',
  password: '',
  confirmPassword: ''
})

// 状态管理
const isLoading = ref(false)
const showModal = ref(false)
const modalType = ref('')
const modalTitle = ref('')

// 头像选项
const avatarOptions = ref([
  { id: '1', url: '/images/avatar1.png' },
  { id: '2', url: '/images/avatar2.png' },
  { id: '3', url: '/images/avatar3.png' },
  { id: '4', url: '/images/avatar4.png' },
  { id: '5', url: '/images/avatar5.png' },
  { id: '6', url: '/images/avatar6.png' }
])

// 粒子系统
let animationId = null
let particles = []

// 初始化背景动效
const initBackground = () => {
  const canvas = backgroundCanvas.value
  if (!canvas) return
  
  const ctx = canvas.getContext('2d')
  
  // 设置canvas尺寸
  const resizeCanvas = () => {
    canvas.width = window.innerWidth
    canvas.height = window.innerHeight
  }
  
  resizeCanvas()
  window.addEventListener('resize', resizeCanvas)
  
  // 创建粒子
  const createParticles = () => {
    particles = []
    const particleCount = 80
    
    for (let i = 0; i < particleCount; i++) {
      particles.push({
        x: Math.random() * canvas.width,
        y: Math.random() * canvas.height,
        radius: Math.random() * 3 + 1,
        speedX: (Math.random() - 0.5) * 2,
        speedY: (Math.random() - 0.5) * 2,
        color: `rgba(${100 + Math.random() * 155}, ${150 + Math.random() * 105}, ${200 + Math.random() * 55}, ${Math.random() * 0.8 + 0.2})`,
        life: Math.random() * 100,
        maxLife: 100 + Math.random() * 100
      })
    }
  }
  
  // 动画循环
  const animate = () => {
    ctx.clearRect(0, 0, canvas.width, canvas.height)
    
    // 更新和绘制粒子
    particles.forEach((particle, index) => {
      // 更新位置
      particle.x += particle.speedX
      particle.y += particle.speedY
      particle.life += 1
      
      // 边界检测
      if (particle.x < 0 || particle.x > canvas.width) particle.speedX *= -1
      if (particle.y < 0 || particle.y > canvas.height) particle.speedY *= -1
      
      // 生命周期
      if (particle.life > particle.maxLife) {
        particle.x = Math.random() * canvas.width
        particle.y = Math.random() * canvas.height
        particle.life = 0
      }
      
      // 绘制粒子
      ctx.beginPath()
      ctx.arc(particle.x, particle.y, particle.radius, 0, Math.PI * 2)
      ctx.fillStyle = particle.color
      ctx.fill()
      
      // 连接线
      particles.forEach((otherParticle, otherIndex) => {
        if (index !== otherIndex) {
          const distance = Math.sqrt(
            Math.pow(particle.x - otherParticle.x, 2) + 
            Math.pow(particle.y - otherParticle.y, 2)
          )
          
          if (distance < 150) {
            ctx.beginPath()
            ctx.moveTo(particle.x, particle.y)
            ctx.lineTo(otherParticle.x, otherParticle.y)
            ctx.strokeStyle = `rgba(150, 200, 255, ${(150 - distance) / 150 * 0.3})`
            ctx.lineWidth = 1
            ctx.stroke()
          }
        }
      })
    })
    
    animationId = requestAnimationFrame(animate)
  }
  
  createParticles()
  animate()
}

// 头像选择
const selectAvatar = (avatarId) => {
  registerForm.avatar = avatarId
}


// 表单验证
const validateForm = () => {
  // 清空之前的错误
  Object.keys(errors).forEach(key => {
    errors[key] = ''
  })

  let isValid = true

  // 用户名验证
  if (registerForm.username.length < 3) {
    errors.username = '用户名至少需要3个字符'
    isValid = false
  }


  // 密码验证
  if (registerForm.password.length < 6) {
    errors.password = '密码至少需要6个字符'
    isValid = false
  }

  // 确认密码验证
  if (registerForm.password !== registerForm.confirmPassword) {
    errors.confirmPassword = '两次输入的密码不一致'
    isValid = false
  }

  return isValid
}

import { authAPI } from '@/api/auth'
// 注册处理
const handleRegister = async () => {
  if (!validateForm()) {
    return
  }

  isLoading.value = true
  try {
    // 只传递后端需要的字段
    const payload = {
      username: registerForm.username,
      password: registerForm.password,
      confirmPassword: registerForm.confirmPassword,
      avatar: registerForm.avatar
    }
    const res = await authAPI.register(payload)
    if (res.code === 1000) {
      window.alert('注册成功，请登录！')
      router.push('/auth/login')
    } else {
      window.alert(res.message || '注册失败')
    }
  } catch (error) {
    if (error.response && error.response.data && error.response.data.message) {
      window.alert(error.response.data.message)
    } else {
      window.alert('网络错误或服务器异常')
    }
    console.error('注册失败:', error)
  } finally {
    isLoading.value = false
  }
}

// 显示协议
const showTerms = () => {
  modalType.value = 'terms'
  modalTitle.value = '用户协议'
  showModal.value = true
}

const showPrivacy = () => {
  modalType.value = 'privacy'
  modalTitle.value = '隐私政策'
  showModal.value = true
}

const closeModal = () => {
  showModal.value = false
}

// 生命周期
onMounted(() => {
  initBackground()
})

onUnmounted(() => {
  if (animationId) {
    cancelAnimationFrame(animationId)
  }
})
</script>

<style scoped>
.register-page {
  min-height: 100vh;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 50%, #16213e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

/* 背景画布 */
.background-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

/* 动态背景系统 */
.dynamic-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

/* 星云效果 */
.nebula-container {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.nebula {
  position: absolute;
  border-radius: 50%;
  opacity: 0.3;
  animation: nebulaDrift 20s infinite ease-in-out;
}

.nebula-1 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(138, 43, 226, 0.6) 0%, rgba(75, 0, 130, 0.3) 40%, transparent 70%);
  top: 10%;
  left: 10%;
  animation-delay: 0s;
}

.nebula-2 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(25, 25, 112, 0.5) 0%, rgba(72, 61, 139, 0.3) 40%, transparent 70%);
  top: 50%;
  right: 10%;
  animation-delay: -7s;
}

.nebula-3 {
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, rgba(65, 105, 225, 0.4) 0%, rgba(30, 144, 255, 0.2) 40%, transparent 70%);
  bottom: 20%;
  left: 30%;
  animation-delay: -14s;
}

@keyframes nebulaDrift {
  0%, 100% { transform: translate(0, 0) rotate(0deg) scale(1); }
  25% { transform: translate(50px, -30px) rotate(90deg) scale(1.1); }
  50% { transform: translate(-20px, 40px) rotate(180deg) scale(0.9); }
  75% { transform: translate(-40px, -20px) rotate(270deg) scale(1.05); }
}

/* 流星雨 */
.meteor-shower {
  position: absolute;
  width: 100%;
  height: 100%;
}

.meteor {
  position: absolute;
  width: 2px;
  height: 2px;
  background: linear-gradient(45deg, #fff, #00f, transparent);
  border-radius: 50%;
}

.meteor::before {
  content: '';
  position: absolute;
  width: 80px;
  height: 1px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.8), transparent);
  transform: rotate(-45deg);
  transform-origin: 0 0;
}

.meteor-1 {
  top: 10%;
  left: 80%;
  animation: meteorFall 3s infinite linear;
  animation-delay: 0s;
}

.meteor-2 {
  top: 20%;
  left: 60%;
  animation: meteorFall 4s infinite linear;
  animation-delay: -1s;
}

.meteor-3 {
  top: 30%;
  left: 70%;
  animation: meteorFall 3.5s infinite linear;
  animation-delay: -2s;
}

.meteor-4 {
  top: 40%;
  left: 90%;
  animation: meteorFall 5s infinite linear;
  animation-delay: -0.5s;
}

.meteor-5 {
  top: 60%;
  left: 50%;
  animation: meteorFall 3.8s infinite linear;
  animation-delay: -1.8s;
}

@keyframes meteorFall {
  0% {
    transform: translate(0, 0);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translate(-300px, 300px);
    opacity: 0;
  }
}

/* 动态光环 */
.ring-system {
  position: absolute;
  width: 100%;
  height: 100%;
}

.ring {
  position: absolute;
  border: 1px solid rgba(100, 149, 237, 0.3);
  border-radius: 50%;
  animation: ringRotate 15s infinite linear;
}

.ring-1 {
  width: 200px;
  height: 200px;
  top: 20%;
  left: 70%;
  animation-delay: 0s;
}

.ring-2 {
  width: 150px;
  height: 150px;
  top: 60%;
  left: 20%;
  animation-delay: -5s;
}

.ring-3 {
  width: 300px;
  height: 300px;
  top: 40%;
  left: 40%;
  animation-delay: -10s;
}

@keyframes ringRotate {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.2); }
  100% { transform: rotate(360deg) scale(1); }
}

/* 螺旋星系 */
.galaxy-spiral {
  position: absolute;
  width: 100%;
  height: 100%;
}

.spiral-arm {
  position: absolute;
  width: 400px;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(138, 43, 226, 0.5), transparent);
  transform-origin: 0 50%;
  animation: spiralRotate 30s infinite linear;
}

.arm-1 {
  top: 50%;
  left: 50%;
  animation-delay: 0s;
}

.arm-2 {
  top: 50%;
  left: 50%;
  animation-delay: -7.5s;
}

.arm-3 {
  top: 50%;
  left: 50%;
  animation-delay: -15s;
}

.arm-4 {
  top: 50%;
  left: 50%;
  animation-delay: -22.5s;
}

@keyframes spiralRotate {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 闪烁星群 */
.star-cluster {
  position: absolute;
  width: 100%;
  height: 100%;
}

.cluster-star {
  position: absolute;
  width: 2px;
  height: 2px;
  background: #fff;
  border-radius: 50%;
  animation: starTwinkle 2s infinite ease-in-out;
}

.cluster-star:nth-child(1) { top: 15%; left: 20%; animation-delay: 0s; }
.cluster-star:nth-child(2) { top: 25%; left: 80%; animation-delay: -0.3s; }
.cluster-star:nth-child(3) { top: 35%; left: 60%; animation-delay: -0.6s; }
.cluster-star:nth-child(4) { top: 45%; left: 15%; animation-delay: -0.9s; }
.cluster-star:nth-child(5) { top: 55%; left: 75%; animation-delay: -1.2s; }
.cluster-star:nth-child(6) { top: 65%; left: 40%; animation-delay: -1.5s; }
.cluster-star:nth-child(7) { top: 75%; left: 85%; animation-delay: -1.8s; }
.cluster-star:nth-child(8) { top: 85%; left: 25%; animation-delay: -2.1s; }

@keyframes starTwinkle {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.5); }
}

/* 主容器 */
.register-container {
  width: 100%;
  max-width: 420px;
  z-index: 10;
  position: relative;
}

/* 注册卡片 */
.register-card {
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  padding: 2.5rem 2rem;
  position: relative;
  overflow: hidden;
  box-shadow: 
    0 20px 40px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

/* 卡片装饰 */
.card-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
}

.decoration-orbit {
  position: absolute;
  border: 1px solid rgba(138, 43, 226, 0.3);
  border-radius: 50%;
  animation: orbitRotate 20s infinite linear;
}

.orbit-1 {
  width: 100px;
  height: 100px;
  top: -20px;
  right: -20px;
  animation-delay: 0s;
}

.orbit-2 {
  width: 80px;
  height: 80px;
  bottom: -10px;
  left: -10px;
  animation-delay: -10s;
}

@keyframes orbitRotate {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.decoration-particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: linear-gradient(45deg, #8a2be2, #4169e1);
  border-radius: 50%;
  animation: particleFloat 8s infinite ease-in-out;
}

.particle-1 {
  top: 10%;
  right: 15%;
  animation-delay: 0s;
}

.particle-2 {
  bottom: 20%;
  left: 10%;
  animation-delay: -3s;
}

.particle-3 {
  top: 60%;
  right: 10%;
  animation-delay: -6s;
}

@keyframes particleFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); opacity: 0.6; }
  25% { transform: translateY(-20px) rotate(90deg); opacity: 1; }
  50% { transform: translateY(0) rotate(180deg); opacity: 0.8; }
  75% { transform: translateY(20px) rotate(270deg); opacity: 1; }
}

/* 头部样式 */
.register-header {
  text-align: center;
  margin-bottom: 2rem;
}

.logo-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 0.75rem;
}

.logo-container {
  position: relative;
  margin-bottom: 0.75rem;
}

.logo-bg {
  width: 70px;
  height: 70px;
  background: linear-gradient(135deg, #8a2be2 0%, #4169e1 100%);
  border-radius: 50%;
  position: relative;
  animation: logoGlow 3s infinite ease-in-out;
}

.logo-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.5rem;
  animation: logoFloat 2s infinite ease-in-out;
}

@keyframes logoGlow {
  0%, 100% { box-shadow: 0 0 20px rgba(138, 43, 226, 0.5); }
  50% { box-shadow: 0 0 40px rgba(138, 43, 226, 0.8), 0 0 60px rgba(65, 105, 225, 0.4); }
}

@keyframes logoFloat {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.1); }
}

.register-header h2 {
  color: #fff;
  font-size: 2.2rem;
  font-weight: 700;
  margin: 0;
  background: linear-gradient(135deg, #fff 0%, #e0e0ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.register-header p {
  color: rgba(255, 255, 255, 0.8);
  font-size: 1rem;
  margin: 0.25rem 0 0 0;
}

/* 表单样式 */
.register-form {
  margin-bottom: 1.5rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

/* 输入框包装器 */
.input-wrapper {
  position: relative;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  transition: all 0.3s ease;
  height: 64px;
  min-height: 64px;
}

.input-wrapper:focus-within {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(138, 43, 226, 0.6);
  box-shadow: 0 0 0 3px rgba(138, 43, 226, 0.2);
}

.input-wrapper.error {
  border-color: rgba(255, 99, 99, 0.6);
  box-shadow: 0 0 0 3px rgba(255, 99, 99, 0.2);
}

/* 输入框图标 */
.input-icon {
  width: 20px;
  height: 20px;
  color: rgba(255, 255, 255, 0.6);
  margin-right: 1rem;
  flex-shrink: 0;
  min-width: 20px;
  transition: color 0.3s ease;
}

.input-wrapper:focus-within .input-icon {
  color: rgba(138, 43, 226, 0.8);
}

/* 输入框 */
.styled-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: #fff;
  font-size: 1rem;
  height: 100%;
  line-height: 1.4;
}

.styled-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
  transition: color 0.3s ease;
}

.styled-input:focus::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

/* 输入框下划线 */
.input-underline {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, #8a2be2, #4169e1);
  transition: all 0.3s ease;
  transform: translateX(-50%);
}

.input-wrapper:focus-within .input-underline {
  width: 100%;
}

/* 错误文本 */
.error-text {
  color: #ff6b6b;
  font-size: 0.875rem;
  margin-top: 0.5rem;
  display: block;
  padding-left: 1rem;
}

/* 头像选择区域 */
.avatar-section {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 16px;
  padding: 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.section-label {
  display: flex;
  align-items: center;
  margin-bottom: 0.75rem;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 600;
}

.label-icon {
  width: 20px;
  height: 20px;
  margin-right: 0.5rem;
  color: rgba(138, 43, 226, 0.8);
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  justify-items: center;
}

.avatar-option {
  position: relative;
  cursor: pointer;
  transition: all 0.3s ease;
}

.avatar-frame {
  position: relative;
  width: 70px;
  height: 70px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  overflow: hidden;
  transition: all 0.3s ease;
  background: rgba(255, 255, 255, 0.05);
}

.avatar-option:hover .avatar-frame {
  border-color: rgba(138, 43, 226, 0.6);
  transform: scale(1.05);
  box-shadow: 0 0 0 3px rgba(138, 43, 226, 0.2);
}

.avatar-option.selected .avatar-frame {
  border-color: #8a2be2;
  background: rgba(138, 43, 226, 0.1);
  box-shadow: 0 0 0 3px rgba(138, 43, 226, 0.3);
}

.avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(138, 43, 226, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.avatar-option.selected .avatar-overlay {
  opacity: 1;
}

.check-icon {
  width: 24px;
  height: 24px;
  color: #fff;
}

/* 协议区域 */
.agreement-wrapper {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.agreement-label {
  display: flex;
  align-items: flex-start;
  cursor: pointer;
  user-select: none;
  gap: 0.75rem;
}

.agreement-checkbox {
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

.checkmark {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  flex-shrink: 0;
  margin-top: 2px;
}

.agreement-checkbox:checked + .checkmark {
  border-color: #8a2be2;
  background: linear-gradient(135deg, #8a2be2, #4169e1);
}

.agreement-checkbox:checked + .checkmark .check-icon {
  opacity: 1;
  transform: scale(1);
}

.checkmark .check-icon {
  width: 12px;
  height: 12px;
  color: #fff;
  opacity: 0;
  transform: scale(0);
  transition: all 0.3s ease;
}

.agreement-text {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.9rem;
  line-height: 1.5;
  flex: 1;
}

.agreement-link {
  color: #8a2be2;
  text-decoration: none;
  font-weight: 600;
  transition: color 0.3s ease;
}

.agreement-link:hover {
  color: #4169e1;
}

/* 注册按钮 */
.register-button {
  width: 100%;
  background: linear-gradient(135deg, #8a2be2 0%, #4169e1 100%);
  border: none;
  border-radius: 16px;
  padding: 1rem 2rem;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  height: 56px;
  position: relative;
  overflow: hidden;
}

.register-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.register-button:hover::before {
  left: 100%;
}

.register-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px rgba(138, 43, 226, 0.3);
}

.register-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.register-button:disabled:hover {
  transform: none;
  box-shadow: none;
}

.button-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.button-icon {
  width: 20px;
  height: 20px;
}

.loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 卡片底部 */
.card-footer {
  text-align: center;
  margin-bottom: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.login-link {
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.95rem;
}

.footer-link {
  color: #8a2be2;
  text-decoration: none;
  font-weight: 600;
  margin-left: 0.5rem;
  transition: color 0.3s ease;
}

.footer-link:hover {
  color: #4169e1;
}

/* 快速操作 */
.quick-actions {
  text-align: center;
}

.divider {
  position: relative;
  margin: 1.5rem 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
}

.divider span {
  background: rgba(255, 255, 255, 0.05);
  padding: 0 1rem;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.875rem;
  backdrop-filter: blur(10px);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.back-home-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 0.75rem 1.5rem;
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.back-home-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(138, 43, 226, 0.4);
  color: #fff;
  transform: translateY(-1px);
}

.btn-icon {
  width: 18px;
  height: 18px;
}

/* 模态框样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 2rem;
  backdrop-filter: blur(10px);
}

.modal-content {
  width: 100%;
  max-width: 500px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  padding: 2rem;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h3 {
  color: #fff;
  margin: 0;
  font-size: 1.5rem;
}

.close-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.modal-body {
  margin-bottom: 1.5rem;
}

.terms-content,
.privacy-content {
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.6;
}

.terms-content h4,
.privacy-content h4 {
  color: #fff;
  margin-bottom: 1rem;
  font-size: 1.2rem;
}

.terms-content ul,
.privacy-content ul {
  padding-left: 1.5rem;
}

.terms-content li,
.privacy-content li {
  margin-bottom: 0.75rem;
}

.modal-footer {
  text-align: center;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-footer .btn {
  background: linear-gradient(135deg, #8a2be2 0%, #4169e1 100%);
  border: none;
  border-radius: 12px;
  padding: 0.75rem 2rem;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.modal-footer .btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(138, 43, 226, 0.3);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .register-page {
    padding: 1rem;
  }
  
  .register-card {
    padding: 1.75rem 1.25rem;
  }
  
  .register-header h2 {
    font-size: 1.8rem;
  }
  
  .logo-bg {
    width: 55px;
    height: 55px;
  }
  
  .logo-icon {
    font-size: 1.75rem;
  }
  
  .input-wrapper {
    height: 56px;
    min-height: 56px;
  }
  
  .avatar-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .avatar-frame {
    width: 60px;
    height: 60px;
  }
  
  .register-button {
    height: 52px;
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  .register-card {
    padding: 1.25rem 0.75rem;
  }
  
  .register-header h2 {
    font-size: 1.5rem;
  }
  
  .input-wrapper {
    height: 52px;
    min-height: 52px;
    padding: 0 0.75rem;
  }
  
  .input-icon {
    width: 18px;
    height: 18px;
    min-width: 18px;
    margin-right: 0.75rem;
  }
  
  .styled-input {
    font-size: 0.9rem;
  }
  
  .avatar-frame {
    width: 50px;
    height: 50px;
  }
  
  .register-button {
    height: 48px;
  }
}
</style>
